<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	template="/WEB-INF/layout/t.xhtml">

	<ui:define name="title">
		<h:outputText value="Scheda Risorsa" />
	</ui:define>
	<ui:define name="roles">
		<f:attribute name="roles" value="resource" />
	</ui:define>

	<ui:define name="content">
		<h:form enctype="multipart/form-data">
			<center>
				<p:panel header="Gestione Risorsa">
					<h:panelGrid columns="2" style="width: 95%"
						columnClasses="col1,col2">

						<h:outputLabel value="Tipo:" for="tipo" />
						<h:outputText id="tipo" value="#{resourceController.element.type}"
							style="width: 100%;" />

						<h:outputLabel value="Nome:" for="nome" />
						<h:outputText id="nome" value="#{resourceController.element.name}"
							style="width: 100%;" />

						<h:outputLabel value="Scarica il file:" for="fileDownload"
							rendered="#{resourceController.element.type eq 'docs'}" />
						<h:outputLink id="fileDownload"
							value="#{request.contextPath}/docs/#{resourceController.element.name}"
							target="_blank"
							rendered="#{resourceController.element.type eq 'docs'}">
							<h:outputText value="#{resourceController.element.name}" />
						</h:outputLink>

						<h:outputLabel value="Carica il nuovo file:" for="fileUpload"
							rendered="#{resourceController.element.type eq 'img' or resourceController.element.type eq 'docs' or resourceController.element.type eq 'swf'  }" />
						<p:fileUpload mode="simple" id="fileUpload"
							value="#{resourceController.replacementFile}"
							rendered="#{resourceController.element.type eq 'img' or resourceController.element.type eq 'docs' or resourceController.element.type eq 'swf'  }" />

					</h:panelGrid>
					<br />
					<h:graphicImage value="/img/#{resourceController.element.name}"
						rendered="#{resourceController.element.type eq 'img'}" />

					<h:inputTextarea value="#{resourceController.element.text}"
						style="width: 100%; height: 300px;"
						rendered="#{resourceController.element.type eq 'css' or resourceController.element.type eq 'js' }" />
				</p:panel>
				<br /> <br />

				<h:panelGrid columns="3">
					<p:commandButton action="#{resourceController.update}"
						value="Salva le modifiche" ajax="false" />

					<p:commandButton
						action="#{resourceController.delElement(resourceController.element.type, resourceController.element.id)}"
						value="Elimina" immediate="true"
						onclick="if (!confirm('Vuoi davvero eliminare?')) return false" />

					<p:commandButton id="reset" action="#{resourceController.reset}"
						value="Annulla" immediate="true" />

				</h:panelGrid>
			</center>

		</h:form>
	</ui:define>
</ui:composition>